﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;
using CodeDomHelper.Types;

namespace devtm.AutoMapper
{
    [CLSCompliant(false)]
    public class TemplateModelList : ITemplateModel
    {



        public CodeExpression CreateObject()
        {
            var r = Type.Translate(typeof(List<>));
            return new CodeObjectCreateExpression(r.ToString());
        }

        public CodeExpression InsertItem(CodeVariableReferenceExpression item, CodeVariableReferenceExpression target)
        {

            var r = Type.Translate(typeof(List<>));

            return

                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeCastExpression(r.AssemblyQualifiedName, target), "Add")
                        , item);
        }

        public TypeExpression Type { get; set; }

        public string Name { get { return "List"; } }
        public bool IsEnumerable { get { return true; } }
        public bool NeedParameter { get { return false; } }
        public string DescriptionParameter { get { return string.Empty; } }
        public string Parameter { get; set; }
        public string MapperName { get; set; }


       
    }

}
